// pages/charge/charge.js
const VEH = require("../../interfaces/vehicles")
const IFS = require("../../interfaces/interface")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    longitude: '116.481451',
    latitude: '40.006822',
    markers: [],
    polyline: [{
      points: [{
        longitude: '116.481451',
        latitude: '40.006822'
      }, {
        longitude: '116.487847',
        latitude: '40.002607'
      }, {
        longitude: '116.496507',
        latitude: '40.006103'
      }],
      color: "#FF0000DD",
      width: 3,
      dottedLine: true
    }],
    circles: [{
      latitude: '40.007153',
      longitude: '116.491081',
      color: '#FF0000DD',
      fillColor: '#7cb5ec88',
      radius: 400,
      strokeWidth: 2
    }],
    controls: [{
      id: 1,
      iconPath: '../../img/marker_yellow.png',
      position: {
        left: 0,
        top: 300 - 50,
        width: 50,
        height: 50
      },
      clickable: true
    }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onStart()
  {
    if(!this.loginJudge())
      return;
    if(VEH.getVehicleNum()==0)
    {
      wx.showModal({
        title:"无车辆信息",
        content:"是否现在添加车辆?",
        
        success:(res)=>{
          if(res.confirm)
          {
            wx.navigateTo({
              url: '/pages/vehicle/vehicle',
            })
          }
        }
      })
      return
    }
    wx.navigateTo({
      url: '/pages/chargeOpt/chargeOpt'})
  },
  loginJudge(){
    if(!IFS.has_login())
    {
      wx.showModal({
        title:"您尚未登录",
        content:"是否立即登录",
        success:(res)=>{
          if(res.confirm)
          {
            getApp().loginJump()
          }
        }
      })
      return false
    }
    return true
  }
})